package flc.ast.activity;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Intent;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import java.util.ArrayList;
import java.util.List;

import flc.ast.BaseAc;
import flc.ast.bean.QzdBean;
import flc.ast.R;
import flc.ast.adapter.QzdAdapter;
import flc.ast.databinding.ActivityQzdBinding;
import stark.common.basic.event.EventStatProxy;

public class QzdActivity extends BaseAc<ActivityQzdBinding> {

    private List<QzdBean> list=new ArrayList<>();
    private QzdAdapter qzdAdapter;
    public int oldPosition=0;

    @Override
    protected int onCreate() {
        return R.layout.activity_qzd;
    }

    @Override
    protected void initView() {
        EventStatProxy.getInstance().statEvent1(this, mDataBinding.event1Container);
        EventStatProxy.getInstance().statEvent5(this, mDataBinding.event5Container);
        mDataBinding.ivQzdBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });
        qzdAdapter=new QzdAdapter();
        mDataBinding.rvQzdList.setLayoutManager(new LinearLayoutManager(mContext,LinearLayoutManager.VERTICAL,false));
        mDataBinding.rvQzdList.setAdapter(qzdAdapter);
    }

    @Override
    protected void initData() {
        oldPosition=getIntent().getIntExtra("position",0);
        list.clear();
        if (oldPosition==0){
            list.add(new QzdBean("内地5000",true));
            list.add(new QzdBean("外籍或港澳台人员6800",false));
        }else {
            list.add(new QzdBean("内地5000",false));
            list.add(new QzdBean("外籍或港澳台人员6800",true));
        }
        qzdAdapter.setList(list);
        qzdAdapter.setOnItemClickListener(this);
    }

    @Override
    protected void onItemClickCallback(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
        qzdAdapter.getItem(oldPosition).setSelect(false);
        qzdAdapter.notifyItemChanged(oldPosition);
        oldPosition=position;
        qzdAdapter.getItem(position).setSelect(true);
        qzdAdapter.notifyItemChanged(position);
    }

    @Override
    public void onBackPressed() {
        Intent data = new Intent();
        data.putExtra("qzdPosition", oldPosition);
        setResult(RESULT_OK, data);
        finish();
    }
}